package com.wyc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wyc.dao.AllusersMapper;
import com.wyc.pojo.Allusers;
import com.wyc.service.AllusersService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AlluserServiceImp
 * @Author 王韫琛
 * @Date 2020/12/20 20:17
 * @Version 1.0
 */
@Service
public class AlluserServiceImp implements AllusersService {
    @Autowired
    private AllusersMapper allusersDao;
    //登录的判断方法
    @Override
    public boolean findUserByName(String name, String pwd, String permission) {
        Allusers allusers = allusersDao.findUserByName(name);
        System.out.println(permission+"imp");
        if (allusers != null && allusers.getPwd().equals(pwd) && allusers.getPermission().equals(permission)) {
            return true;
        }
        return false;
    }
    //查询所有用户的方法
    @Override
    public List<Allusers> queryAllUser() {
        return allusersDao.queryAllUser(0,1000);
    }
    @Override
    public List<Allusers> queryAllUser(Integer pageNum, Integer pageSize) {
        return null;
    }
    //检查用户名是否存在
    @Override
    public Allusers queryUserName(String username) {
        return allusersDao.queryUserName(username);
    }
    //检查身份证是否存在
    @Override
    public Allusers queryUserIdentityCard(String identity_card) {
        return allusersDao.queryUserIdentityCard(identity_card);
    }
    //普通用户修改密码
    @Override
    public int userUpdatePdw(String pwd, String newpwd,String username) {
        return allusersDao.userUpdatePdw(pwd, newpwd,username);
    }
    //用户查询基本信息
    @Override
    public Allusers basicData(String username) {
        return allusersDao.basicData(username);
    }
    //所有用户修改密码
    @Override
    public int allUserUpdatePwd(String username, String identity_card, String newpwd) {
        System.out.println(username + identity_card + newpwd);
        return allusersDao.allUserUpdatePwd(username, identity_card, newpwd);
    }
    //超级管理员根据身份证查询用户信息
    @Override
    public Allusers SuperSelectByIdentityCard(String identity_card) {
        return allusersDao.SuperSelectByIdentityCard(identity_card);
    }

    //超级管理员分页查询的方法
    public List<Allusers> findPage(Integer pageNum,Integer pageSize){
        //开启静态方法调用
//        PageHelper.startPage(pageNum,pageSize);
        pageNum = (pageNum-1)*pageSize;
        //调用查询的方法
        List<Allusers> list = allusersDao.queryAllUser(pageNum,pageSize);
        return list;
    }
    //用于添加一个用户
    @Override
    public int addUser(Allusers allusers) {
        return allusersDao.addUser(allusers);
    }
    //超级管理员删除用户
    @Override
    public int deleteById(Integer id) {
        return allusersDao.deleteById(id);
    }
    //超级管理员更新用户
    @Override
    public int updateUser(Allusers allusers) {
        return allusersDao.updateUser(allusers);
    }

    @Override
    public int getTotal() {
        return allusersDao.getTotal();
    }

    @Override
    public Allusers queryUser(String identity_card) {
        return allusersDao.queryUser(identity_card);
    }
    //分页查询数据信息
    @Override
    public List<Allusers> adminfFndInforPage(Integer pageNum, Integer pageSize, String permission) {
        pageNum = (pageNum-1)*pageSize;
        List<Allusers> list = allusersDao.adminfFndInforPage(pageNum, pageSize, permission);
        return list;
    }

    @Override
    public int adminGetInforTotal(String permission) {

        return allusersDao.adminGetInforTotal(permission);
    }
    //检查身份证与当前用户注册时候的是否一样
    @Override
    public Allusers SuperSelectByIdentity(String identityCard, String username) {
        return allusersDao.SuperSelectByIdentity(identityCard, username);
    }

    @Override
    public Allusers SuperSelectByUsername(String username) {
        return allusersDao.SuperSelectByUsername(username);
    }
}
